<?php

namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;
use Illuminate\Queue\RedisQueue;
use Auth;
class LoginController extends Controller
{
    public function login(){
    	return view('user.login');
	}
	public function store(Request $request){
		$user=$this->validate ($request,[
			'email'=>'required|email',
			'password'=>'required'
		]);
		$u=User::where('email',$request->input('email'))->first();
		if(!$u->status){
			session()->flash('danger','账户不存在或者未激活！');
			return redirect ()->back();
		}
		if(Auth::attempt ($user,$request->has('remeber'))){
			session()->flash ('success','登录成功');
			return redirect ()->intended (route('home'));
		}
		return redirect ()->back()->withInput ();

	}
	public function logout(){
		Auth::logout ();
		session()->flash('success','退出成功！');
		return redirect ()->route ('login');
	}

}
